package cnn.ecut.dzy;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

/**
 * @program: zk
 * @description:
 * @author: DingZhenYun
 * @create: 2021-09-14 17:06
 **/

public class Test {
    public static void main(String[] args) throws Exception {

         CuratorFramework client;

            //重试策略
            RetryPolicy retryPolicy = new ExponentialBackoffRetry(3000,10);

            //2.第二种方式
            CuratorFrameworkFactory.builder();
            client = CuratorFrameworkFactory.builder()
                    .connectString("192.168.42.10:2181")
                    .sessionTimeoutMs(60 * 1000)
                    .connectionTimeoutMs(15 * 1000)
                    .retryPolicy(retryPolicy)
                    .namespace("dzy")
                    .build();

            //开启连接
            client.start();
            String path = client.create().forPath("/app2");
            System.out.println(path);


    }
}
